#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    string reverseWords(string s) {
        size_t right = 0;
        size_t left = 0;
        while ((right = s.find(' ', left)) != string::npos)
        {
            reverse(s.begin() + left, s.begin() + right);
            left = right + 1;
        }
        reverse(s.begin() + left, s.end());
        return s;
    }
};

int main()
{
    Solution s;
    cout << s.reverseWords("Let's take LeetCode contest") << endl;
    return 0;
}